package com.fingard.dsp.bank.reqrespobj.frgcurrsingle;

import com.fingard.dsp.bank.reqrespobj.ReqRespHeader;
import com.fingard.dsp.bank.reqrespobj.RetAtsBase;
import com.fingard.dsp.bank.reqrespobj.frgcurrsingle.detail.RetAtsCJFrgCurrSingleDetail;
import com.fingard.dsp.bank.reqrespobj.single.ReqSingleBat;
import com.fingard.xml.XmlTextWriter;

/**
 * 财经--单笔合批--海外接口提交或查询返回ATS通用对象
 */
public class RetAtsCJFrgCurrSingleBat extends RetAtsBase{
    public String batRespCode;//批次状态码
    public String batRespInfo;//批次状态信息

    public RetAtsCJFrgCurrSingleBat(ReqRespHeader p_reqHeader) {
        retHeader = p_reqHeader;
        retXmlWriter = new XmlTextWriter();//用于输出返回ATS的XML报文
    }

    public RetAtsCJFrgCurrSingleBat(ReqSingleBat p_reqBat) {
        retHeader = p_reqBat.reqHeader;
        retXmlWriter = new XmlTextWriter();//用于输出返回ATS的XML报文
    }

    private int writeRdCount = 0;

    public int getWrittenRdCount() {
        return writeRdCount;
    }

    public void writeRetDetail(RetAtsCJFrgCurrSingleDetail p_retDetail) throws Exception {
        if (!hasWrittenBefore) {
            writeBeforeDetail();
        }
        writeRdCount++;
        retXmlWriter.writeStartElement("DetailRecord");
        retXmlWriter.writeElementString("RespCode", p_retDetail.respCode);
        retXmlWriter.writeElementString("RespInfo", p_retDetail.respInfo);
        retXmlWriter.writeElementString("TransState", p_retDetail.transState);
        retXmlWriter.writeElementString("ReqSeqID", p_retDetail.reqSeqID);
        retXmlWriter.writeElementString("PayInfoCode", p_retDetail.payInfoCode);
        retXmlWriter.writeElementString("TransAmt", p_retDetail.transAmt);
        retXmlWriter.writeElementString("ResendFlag",p_retDetail.resendFlag);
        retXmlWriter.writeElementString("OutTransID", p_retDetail.outTransID);
        retXmlWriter.writeEndElement();
    }

    private boolean hasWrittenBefore = false;


    public void writeBeforeDetail() throws Exception {
        if (hasWrittenBefore) {
            throw new Exception("writeBeforeDetail已被调用过");
        }
        writeStart();//写返回ATS的统一头部信息
        retXmlWriter.writeElementString("BatRespCode", batRespCode);
        retXmlWriter.writeElementString("BatRespInfo", batRespInfo);
        hasWrittenBefore = true;
    }

    public void writeAfterDetail() throws Exception {
        if (!hasWrittenBefore) {
            writeBeforeDetail();
        }
        writeEnd();//写结束
    }
}
